/**
 * 应用常量定义
 */

// 应用信息
export const APP_INFO = {
  NAME: 'SLYT Script Assistant',
  VERSION: '1.0.0',
  DESCRIPTION: '轻量级脚本录制助手',
  AUTHOR: 'SLYT Team'
}

// API 端点
export const API_ENDPOINTS = {
  BASE_URL: import.meta.env.VITE_API_BASE_URL || 'http://localhost:3000',
  RECORDING_SERVER_URL: import.meta.env.VITE_RECORDING_SERVER_URL || 'http://localhost:3001',
  HEALTH: '/health',
  RECORDING: {
    BASE: '/api/recording',
    START: '/api/recording/start',
    STOP: '/api/recording/stop',
    STATUS: '/api/recording/status',
    RESULT: '/api/recording/result',
    SESSIONS: '/api/recording/sessions'
  },
  SCRIPTS: {
    BASE: '/api/scripts',
    LIST: '/api/scripts/list',
    SAVE: '/api/scripts/save',
    LOAD: '/api/scripts/load',
    DELETE: '/api/scripts/delete',
    IMPORT: '/api/scripts/import',
    EXPORT: '/api/scripts/export',
    VALIDATE: '/api/scripts/validate',
    FORMAT: '/api/scripts/format',
    CONVERT: '/api/scripts/convert',
    EXECUTE: '/api/scripts/execute'
  }
}

// 脚本格式
export const SCRIPT_FORMATS = {
  PLAYWRIGHT: 'playwright',
  JSONL: 'jsonl',
  JSON: 'json'
}

// 步骤类型
export const STEP_TYPES = {
  NAVIGATE: 'navigate',
  INPUT: 'input',
  CLICK: 'click',
  SELECT: 'select',
  CHECKBOX: 'checkbox',
  WAIT: 'wait',
  SCREENSHOT: 'screenshot',
  ASSERTION: 'assertion',
  ACTION: 'action'
}

// 执行状态
export const EXECUTION_STATUS = {
  IDLE: 'idle',
  PREPARING: 'preparing',
  EXECUTING: 'executing',
  COMPLETED: 'completed',
  ERROR: 'error',
  PAUSED: 'paused'
}

// 步骤执行状态
export const STEP_STATUS = {
  PENDING: 'pending',
  EXECUTING: 'executing',
  SUCCESS: 'success',
  ERROR: 'error',
  SKIPPED: 'skipped'
}

// 录制状态
export const RECORDING_STATUS = {
  IDLE: 'idle',
  STARTING: 'starting',
  RECORDING: 'recording',
  STOPPING: 'stopping',
  COMPLETED: 'completed',
  ERROR: 'error'
}

// 设备类型
export const DEVICE_TYPES = {
  DESKTOP: 'desktop',
  MOBILE: 'mobile',
  TABLET: 'tablet'
}

// 默认配置
export const DEFAULT_CONFIG = {
  RECORDING: {
    WIDTH: 1280,
    HEIGHT: 720,
    DEVICE: DEVICE_TYPES.DESKTOP,
    HEADLESS: false,
    TIMEOUT: 30000,
    WAIT_FOR_LOAD_STATE: 'domcontentloaded'
  },
  EXECUTION: {
    TIMEOUT: 30000,
    RETRY_COUNT: 3,
    CONTINUE_ON_ERROR: false,
    HEADLESS: true,
    SLOW_MO: 0,
    SCREENSHOT: 'only-on-failure'
  },
  UI: {
    SHOW_LINE_NUMBERS: true,
    SHOW_STEP_ICONS: true,
    SHOW_EXECUTION_TIME: true,
    COMPACT_MODE: false,
    SPLIT_PANEL_RATIO: 0.4,
    AUTO_SAVE: true,
    AUTO_SAVE_INTERVAL: 30000
  }
}

// 文件类型
export const FILE_TYPES = {
  JAVASCRIPT: 'js',
  PLAYWRIGHT: 'playwright',
  JSONL: 'jsonl',
  JSON: 'json',
  TEXT: 'txt'
}

// MIME 类型
export const MIME_TYPES = {
  [FILE_TYPES.JAVASCRIPT]: 'text/javascript',
  [FILE_TYPES.PLAYWRIGHT]: 'text/javascript',
  [FILE_TYPES.JSONL]: 'application/x-jsonlines',
  [FILE_TYPES.JSON]: 'application/json',
  [FILE_TYPES.TEXT]: 'text/plain'
}

// 日志级别
export const LOG_LEVELS = {
  DEBUG: 'debug',
  INFO: 'info',
  WARN: 'warn',
  ERROR: 'error'
}

// 主题
export const THEMES = {
  LIGHT: 'light',
  DARK: 'dark',
  AUTO: 'auto'
}

// 语言
export const LANGUAGES = {
  ZH_CN: 'zh-CN',
  EN_US: 'en-US'
}

// 错误代码
export const ERROR_CODES = {
  NETWORK_ERROR: 'NETWORK_ERROR',
  API_ERROR: 'API_ERROR',
  VALIDATION_ERROR: 'VALIDATION_ERROR',
  RECORDING_ERROR: 'RECORDING_ERROR',
  EXECUTION_ERROR: 'EXECUTION_ERROR',
  PARSING_ERROR: 'PARSING_ERROR',
  FILE_ERROR: 'FILE_ERROR',
  UNKNOWN_ERROR: 'UNKNOWN_ERROR'
}

// 本地存储键
export const STORAGE_KEYS = {
  CONFIG: 'slyt-config',
  RECENT_FILES: 'slyt-recent-files',
  ERROR_LOGS: 'slyt-error-logs',
  USER_PREFERENCES: 'slyt-user-preferences',
  SCRIPT_CACHE: 'slyt-script-cache'
}

// 事件名称
export const EVENT_NAMES = {
  RECORDING: {
    CONNECTED: 'recording:connected',
    DISCONNECTED: 'recording:disconnected',
    STEP: 'recording:step',
    STATUS: 'recording:status',
    ERROR: 'recording:error',
    COMPLETE: 'recording:complete'
  },
  EXECUTION: {
    START: 'execution:start',
    STEP: 'execution:step',
    COMPLETE: 'execution:complete',
    ERROR: 'execution:error',
    PAUSE: 'execution:pause',
    RESUME: 'execution:resume',
    STOP: 'execution:stop'
  },
  UI: {
    MODAL_OPEN: 'ui:modal:open',
    MODAL_CLOSE: 'ui:modal:close',
    THEME_CHANGE: 'ui:theme:change',
    LANGUAGE_CHANGE: 'ui:language:change'
  }
}

// 验证规则
export const VALIDATION_RULES = {
  SCRIPT_NAME: {
    MIN_LENGTH: 1,
    MAX_LENGTH: 100,
    PATTERN: /^[a-zA-Z0-9\u4e00-\u9fa5_\-\s\.]+$/
  },
  URL: {
    PATTERN: /^https?:\/\/.+/
  },
  SELECTOR: {
    MIN_LENGTH: 1,
    MAX_LENGTH: 500
  },
  TIMEOUT: {
    MIN: 1000,
    MAX: 300000
  }
}

// 快捷键
export const SHORTCUTS = {
  SAVE: 'Ctrl+S',
  IMPORT: 'Ctrl+O',
  EXPORT: 'Ctrl+E',
  START_RECORDING: 'Ctrl+R',
  STOP_RECORDING: 'Ctrl+Shift+R',
  EXECUTE: 'F5',
  STOP_EXECUTION: 'Shift+F5',
  TOGGLE_FULLSCREEN: 'F11',
  CLEAR_LOGS: 'Ctrl+L',
  NEW_SCRIPT: 'Ctrl+N'
}

// 动画持续时间
export const ANIMATION_DURATION = {
  FAST: 150,
  NORMAL: 300,
  SLOW: 500
}

// 分页配置
export const PAGINATION = {
  DEFAULT_PAGE_SIZE: 20,
  PAGE_SIZE_OPTIONS: [10, 20, 50, 100]
}

// 文件大小限制
export const FILE_SIZE_LIMITS = {
  SCRIPT_FILE: 10 * 1024 * 1024, // 10MB
  LOG_FILE: 50 * 1024 * 1024,    // 50MB
  SCREENSHOT: 5 * 1024 * 1024     // 5MB
}

export default {
  APP_INFO,
  API_ENDPOINTS,
  SCRIPT_FORMATS,
  STEP_TYPES,
  EXECUTION_STATUS,
  STEP_STATUS,
  RECORDING_STATUS,
  DEVICE_TYPES,
  DEFAULT_CONFIG,
  FILE_TYPES,
  MIME_TYPES,
  LOG_LEVELS,
  THEMES,
  LANGUAGES,
  ERROR_CODES,
  STORAGE_KEYS,
  EVENT_NAMES,
  VALIDATION_RULES,
  SHORTCUTS,
  ANIMATION_DURATION,
  PAGINATION,
  FILE_SIZE_LIMITS
}

